package com.ibeifeng.crm.dao.impl;

import java.util.HashSet;
import java.util.Set;

import javax.annotation.Resource;

import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.log4j.Logger;
import org.springframework.stereotype.Repository;

import com.ibeifeng.crm.bean.User;
import com.ibeifeng.crm.dao.UserFindDao;

@Repository
public class UserFindDaoImpl implements UserFindDao {
	Logger log = Logger.getLogger(UserFindDaoImpl.class);
	@Resource
	SqlSessionFactory factory;
	
	@Override
	public User findUserByUsreCode(String userCode) {
		User user= factory.openSession().selectOne("com.ibeifeng.crm.user.bean.mapping.UserNS.findUserByUsreCode",userCode);
		return user;
	}

	@Override
	public Set<String> findAllRoleByUsreCode(String userCode) {
		Set<String> set=new HashSet<String>();
		set.add((String) factory.openSession().selectOne("com.ibeifeng.crm.user.bean.mapping.UserNS.findAllRoleByUsreCode",userCode));
		return set;
	}

	@Override
	public Set<String> findAllPermissionByUsreCode(String userCode) {
		Set<String> set=new HashSet<String>();
		String str=factory.openSession().selectOne("com.ibeifeng.crm.user.bean.mapping.UserNS.findAllPermissionByUsreCode",userCode);
		String[] split = str.split(",");
		for (int i = 0; i < split.length; i++) {
			set.add(split[i]);
		}
		return set;
	}

}
